package com.example.permissionsystem1_1.businessFunction.service.converter;

import com.example.permissionsystem1_1.businessFunction.dao.entity.po.DepartmentUserPo;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSelectAllDepartmentsByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.departmentUserReqModel.DepartmentUserSetDepartmentUserRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSelectAllDepartmentsByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.departmentUserRspModel.DepartmentUserSetDepartmentUserRelationRspModel;
import com.example.permissionsystem1_1.common.businessFunction.BaseServiceConverter;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class DepartmentUserServiceConverter extends BaseServiceConverter {
    //1.selectAllDepartmentsByUserId
    public static DepartmentUserPo convertReqModelToPo(DepartmentUserSelectAllDepartmentsByUserIdReqModel reqModel) {
        if (reqModel == null || reqModel.getUserId()==null) {
            return null;
        }
        DepartmentUserPo po=new DepartmentUserPo();
        BeanUtils.copyProperties(reqModel, po);
        return po;
    }
    public static DepartmentUserSelectAllDepartmentsByUserIdRspModel covertToSelectAllDepartmentsByUserIdModel(List<DepartmentUserPo> pos) {
        if( pos == null) {
            return null;
        }
        DepartmentUserSelectAllDepartmentsByUserIdRspModel rspModel=new DepartmentUserSelectAllDepartmentsByUserIdRspModel();
        if(pos.size()>0){
            List<DepartmentUserRspModel> departmentUserRspModels=new ArrayList<>();
            for (DepartmentUserPo po:pos) {
                DepartmentUserRspModel departmentUserRspModel=new DepartmentUserRspModel();
                BeanUtils.copyProperties(po, departmentUserRspModel);
                departmentUserRspModels.add(departmentUserRspModel);
            }
            rspModel.setDepartmentUserRspModels(departmentUserRspModels);
        }
        return rspModel;
    }
    //2.setDepartmentUserRelation
    public static DepartmentUserPo convertReqModelToPo(DepartmentUserSetDepartmentUserRelationReqModel reqModel) {
        if (reqModel == null || reqModel.getUserId()==null || reqModel.getDepartmentId()==null) {
            return null;
        }
        DepartmentUserPo po=new DepartmentUserPo();
        BeanUtils.copyProperties(reqModel, po);
        setDefaultAttributesValue(po);
        return po;
    }
    public static DepartmentUserSetDepartmentUserRelationRspModel covertToSetDepartmentUserRelationModel(Integer i) {
        DepartmentUserSetDepartmentUserRelationRspModel rspModel=new DepartmentUserSetDepartmentUserRelationRspModel();
        rspModel.setResultSum(i);
        return rspModel;
    }




}
